package cc.comac.mom.util;

import java.time.LocalDateTime;
import java.util.Date;

public class FrequencyUtil {

    // 通过计划首次开始时间和循环周期算出结束时间
    public static  Date getCycleDataToDateTime(String unit, int cycleValue, Date firstPlanDateStart) {
        LocalDateTime firstDate=TimeUtil.fomatDateToLocalDateTime(firstPlanDateStart);
        LocalDateTime dateTime = null;
        switch (unit) {
            case "hour":
                dateTime = firstDate.plusHours(cycleValue);
                break;
            case "day":
                dateTime = firstDate.plusDays(cycleValue);
                break;
            case "week":
                dateTime = firstDate.plusDays(cycleValue * 7);
                break;
            case "month":
                dateTime = firstDate.plusMonths(cycleValue);
                break;
            case "quarter":
                dateTime = firstDate.plusMonths(cycleValue * 3);
                break;
            case "year":
                dateTime = firstDate.plusYears(cycleValue);
                break;
            default:
                throw new RuntimeException("传入数据无法转换时间！");
        }
        return TimeUtil.fomatLocalDateTimeToDate(dateTime);
    }

    // 通过计划首次开始时间和循环周期算出结束时间
    public static  LocalDateTime getCycleDataToLocalDateTime(String unit, int cycleValue, LocalDateTime firstPlanDateStart) {
        LocalDateTime dateTime = null;
        switch (unit) {
            case "hour":
                dateTime = firstPlanDateStart.plusHours(cycleValue);
                break;
            case "day":
                dateTime = firstPlanDateStart.plusDays(cycleValue);
                break;
            case "week":
                dateTime = firstPlanDateStart.plusDays(cycleValue * 7);
                break;
            case "month":
                dateTime = firstPlanDateStart.plusMonths(cycleValue);
                break;
            case "quarter":
                dateTime = firstPlanDateStart.plusMonths(cycleValue * 3);
                break;
            case "year":
                dateTime = firstPlanDateStart.plusYears(cycleValue);
                break;
            default:
                throw new RuntimeException("传入数据无法转换时间！");
        }
        return dateTime;
    }

    // 将1周、1月等数据转换为具体多少小时
    public static int getCycleDataToHouse(String unit,int cycleValue) {
        int totalHouse = 0;
        switch (unit) {
            case "hour":
                totalHouse = cycleValue;
                break;
            case "day":
                totalHouse = cycleValue * 24;
                break;
            case "week":
                totalHouse = cycleValue * 7 * 24;
                break;
            case "month":
                totalHouse = cycleValue * 30 * 24;
                break;
            case "quarter":
                totalHouse = cycleValue * 3 * 30 * 24;
                break;
            case "year":
                totalHouse = cycleValue * 12 * 30 * 24;
                break;
            default:
                throw new RuntimeException("传入数据无法转换时间！");
        }
        return totalHouse;
    }
    
    public static LocalDateTime getAddDataByUnit(Date startTime,String unit,int cycleValue,int cycleInt) {
		  LocalDateTime startDate = TimeUtil.fomatDateToLocalDateTime(startTime);
    	switch (unit) {
          case "hour":
          	startDate = startDate.plusHours(cycleValue*cycleInt);
              break;
          case "day":
          	startDate = startDate.plusDays(cycleValue*cycleInt);
              break;
          case "week":
          	startDate = startDate.plusWeeks(cycleValue*cycleInt);
              break;
          case "month":
          	startDate = startDate.plusMonths(cycleValue*cycleInt);
              break;
          case "quarter":
          	startDate = startDate.plusMonths(3*cycleValue*cycleInt);
              break;
          case "year":
          	startDate =startDate.plusYears(cycleValue*cycleInt);
              break;
          default:
              throw new RuntimeException("传入数据无法转换时间！");
      }
        return startDate;
    }
}
